package db

import (
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"gorm.io/gorm/schema"
)

// 数据库驱动
func ConnMysql() *gorm.DB {
	datasource := "root:root@tcp(127.0.0.1:3306)/account?charset=utf8mb4&parseTime=True&loc=Local"
	db, err := gorm.Open(mysql.Open(datasource), &gorm.Config{
		//配置查询表名时自动加s
		NamingStrategy: schema.NamingStrategy{
			SingularTable: true,
		},
	})
	if err != nil {
		fmt.Println("error connect mysql", err)
	}
	return db
}

//定义数据表映射结构体

type User struct {
	Id       int    `json:"id"`
	User     string `json:"user"`
	Password string `json:"password"`
	Role     string `json:"role"`
}
